const express = require("express");

const Collect = require("../../models/Collect");

const router = express.Router({
  mergeParams: true,
});

//删除收藏
router.delete("/user/collects/:id", async (req, res) => {
  const id = req.params.id;
  const model = await Collect.findOneAndDelete(id);
  message = "fail";
  if (model) {
    message = "success";
  }
  res.send({
    message,
  });
});

//创建收藏
router.post("/collect", async (req, res) => {
  const model = await Collect.create(req.body);
  res.send(model);
});


//查询收藏
router.get("/user/collects/:id",async(req,res)=>{
  const id=req.params.id;
  const itmes = await Collect.where({userId:id}).find();
  res.send(itmes);
});


module.exports = router;
